<div class="notification-main">
	<div class="History-box">
	  <h1 class="title">Watchlist</h1>

     <?php $this->widget('zii.widgets.grid.CGridView', 
  array(
  'id'=>'product-grid',
  'dataProvider'=>$watchlist->search_my(),
  // 'filter'=>$model,
  'template'=>"{items}\n{summary}\n{pager}",


  'columns'=>array(
    array(
      'type'=>'raw',
      'name'=>'Auction Title',
      'value' => function($data){return "<a href='".Yii::app()->baseUrl."/index/detail?auction_id=".$data->AuctionInfo->id."'>".$data->AuctionInfo->title."</a>";},
      ),
    array(
      'name'=>'Price',
      'value' => '$data->AuctionInfo->status==2?$data->AuctionInfo->winner_price:$data->AuctionInfo->AuctionPool->winner_price',
      ),
    array(
      'name'=>'Status',
      'value' => function($data){switch ($data->AuctionInfo->status) {
                                              case '0':
                                              return 'About to run';
                                              break;
                                              case '1':
                                              return 'Live';
                                              break;
                                              case '2':
                                              return 'Close';
                                              break;
                                               };
                                  },
      ),
    array(
      'type'=>'raw',
      'name'=>'Operation',
      'value' => function($data){ return "<button class='btn submit-btn cancel' id='search' onclick=cancel($(this),".Yii::app()->user->id.",".$data->AuctionInfo->id.")>Remove</button>";},
      ),
    ),
)); ?>
    <!--
		<table width="848" border="1" class="datalist">
  <tr>
    <td width="510" align="center" valign="middle" class="rowone">Product</td>
    <td width="216" align="center" valign="middle" class="rowone">Price</td>
    <td width="100" align="center" valign="middle" class="rowone">Status</td>
    <td width="100" align="center" valign="middle" class="rowone">&nbsp;</td>
  </tr>
  <?php  
  foreach ($watchlist as $k => $v) {
    // var_dump($v['AuctionInfo']['title']);exit;
      if($k%2==0){
  ?>

  <tr>
    <td align="center"><?php echo $v['AuctionInfo']['title']?></td>
    <td align="center"><?php echo $v['AuctionInfo']['winner_price']?></td>
    <td align="center"><?php switch ($v['AuctionInfo']['status']) {
      case '0':
      echo 'About to run';
        break;
      case '1':
      echo 'Running';
        break;
      case '2':
      echo 'Close';
        break;
      }?></td>
    <td align="center"><button class="btn btn-bid-auction cancel" id="search" onclick=cancel($(this),<?php echo Yii::app()->user->id;?>,<?php echo $v['AuctionInfo']['id'];?>) >cancel</button></td>
  </tr>
    <?php }else{?>
  <tr class="heavy">
    <td align="center"><?php echo $v['AuctionInfo']['title']?></td>
    <td align="center"><?php echo $v['AuctionInfo']['winner_price']?></td>
    <td align="center"><?php switch ($v['AuctionInfo']['status']) {
      case '0':
      echo 'About to run';
        break;
      case '1':
      echo 'Running';
        break;
      case '2':
      echo 'Close';
        break;
      }?></td>
    <td align="center"><button class="btn btn-bid-auction cancel" id="search" onclick=cancel($(this),<?php echo Yii::app()->user->id;?>,<?php echo $v['AuctionInfo']['id'];?>) >Remove</button></td>
  </tr>
  <?php  
  }}
  ?>
</table>
-->
	</div>
</div>
<script type="text/javascript">
var button;
function cancel(bobj,cid,aid){
  buttonObj = bobj;
  $.post("<?php echo Yii::app()->baseUrl;?>/auctions/watchit",{cid:cid,aid:aid},function(data){
    if(data==1){
      if(buttonObj.text()=="Remove"){
        buttonObj.text("watch");
      }
      else if(buttonObj.text()=="watch"){
        buttonObj.text("Remove");
      }
    }
  })
}
</script>